package com.yihu.wlyy.repository;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.yihu.wlyy.entity.consult.ConsultTeamDoctor;

public interface ConsultTeamDoctorDao extends PagingAndSortingRepository<ConsultTeamDoctor, Long>, JpaSpecificationExecutor<ConsultTeamDoctor> {

	@Query("select count(1) from ConsultTeamDoctor a where a.consult = ?1 and a.to = ?2")
	int isExist(String consult, String doctor);

	// 更新为有回复
	@Modifying
	@Query("update ConsultTeamDoctor a set a.reply = 1 where a.consult = ?1 and a.to = ?2")
	int updateReply(String consult, String doctor);

	@Query("select a from ConsultTeamDoctor a where a.consult = ?1 and a.del = '1'")
	Iterable<ConsultTeamDoctor> findByConsult(String consult);

	// 查询有回复过的医生
	@Query("select a.to from ConsultTeamDoctor a where a.consult = ?1 and a.reply = 1 and a.del = '1'")
	String[] findReplyDoctor(String consult);

	@Query("select count(a) from ConsultTeamDoctor a where a.to = ?1 and a.del = '1'")
	long getAllCountByDoctorCode(String doctorCode);
	
	@Query("select count(a) from ConsultTeamDoctor a where a.to = ?1 and a.del = '1' and date(a.czrq) = curdate() ")
	long getTodayCountByDoctorCode(String doctorCode);

	@Query(" from ConsultTeamDoctor a where a.consult=?1 and a.to = ?2 and a.del = '1' ")
	ConsultTeamDoctor getByConsultCodeAndDoctorCode(String consultCode, String code);
}
